package ltd.bean;

import io.netty.channel.ChannelHandlerContext;
import io.netty.channel.group.DefaultChannelGroup;
import io.netty.util.concurrent.GlobalEventExecutor;

import java.util.HashMap;
import java.util.Map;


public class ChannelGroup {
	
	private static final ChannelGroup INSTANCE = new ChannelGroup();
	
	private ChannelGroup() {
		super();
	}
	
	public static ChannelGroup getInstance(){
		return INSTANCE;
	}

	/** 框架默认的 Channel 组 */
	private final io.netty.channel.group.ChannelGroup channelGroup = new DefaultChannelGroup(GlobalEventExecutor.INSTANCE);
	
	/**
	 * 用户 Channel Map 集合
	 * 以Channel的ID做为键值
	 */
	private Map<String, ChannelHandlerContext> channelMap = new HashMap<String, ChannelHandlerContext>();
	
	/**
	 * 所有Session Map 集合 (包含服务器和用户)
	 * 以Channel的ID做为键值
	 */
	private Map<String, Session> sessionMap = new HashMap<String, Session>();

	/**
	 * 游戏服务器Session Map 集合
	 * 以 gameID做为键值
	 */
	private Map<Integer, Session> gameMap = new HashMap<Integer, Session>();

	public synchronized io.netty.channel.group.ChannelGroup getChGroup(){
		return channelGroup;
	}

	public synchronized Map<String, ChannelHandlerContext> getChannelMap(){
		return channelMap;
	}

	public synchronized Map<String, Session> getSessionMap(){
		return sessionMap;
	}

	public synchronized Map<Integer, Session> getGameMap(){
		return gameMap;
	}
}
